<template>

  <view class="container">
    <view>
      <i-cell-group>
        <i-cell title="UID" v-model="user.id"></i-cell>
        <i-cell title="头像" is-link url="/pages/settings/avatar_edit">
          <i-avatar slot="footer" :src="user.avatarUrl" size="default" shape="square"></i-avatar>
        </i-cell>
        <i-cell title="姓名" v-model="user.name" is-link url="/pages/settings/name_edit"></i-cell>
        <i-cell title="手机号" v-model="user.mobile" is-link url="/pages/user/modify_mobile"></i-cell>
      </i-cell-group>
    </view>
    <div class="cancel-login-btn" @tap="cancelLoginStatus()">退出登录</div>
  </view>

</template>

<script>
import wxRequest from '@/utils/wxRequest';
import Session from '@/utils/session';

export default {
  data() {
    return {

        user: {}

    };
  },

  onShow() {
    this.getUser();
  },

  mixins: [],
  components: {},
  props: {},
  methods: {
    async uploadUserAvatar() {
      const choseImages = await uni.chooseImage({
        count: 1,
        sizeType: ['compressed'],
        sourceType: ['album', 'camera']
      });

      if (choseImages.tempFiles.length == 0) {
        wx.showToast({
          title: '上传失败， 请稍后再试',
          icon: 'none',
          mask: false,
          duration: 1000
        });
        return false;
      }

      await wxRequest.Upload(choseImages.tempFiles[0].path, {
        type: 'user_avatar'
      });
      this.getUser();
    },

    async cancelLoginStatus() {
      await wxRequest.Put('wx-logout'); //通知Tab页面需要刷新

      for (let index = 0; index < 5; index++) {
        Session.set('page-' + index, true);
      }

      wx.navigateBack({
        delta: 1
      });
    },

    async getUser() {
      const data = await wxRequest.Get('settings');
      this.user = data.result.user;
    }

  },
  computed: {},
  watch: {}
};
</script>
<style lang="scss">

  page {
    background: #f4f4f4;
  }
  .my-avatar {
    width: 35px;
    height: 35px;
  }
  .notice-remind {
    display: flex;
    justify-content: space-between;
    padding: 12px 15px;
    background: white;
    .notice-title {
      font-size: 14px;
    }
    .notice-time {
      font-size: 12px;
      padding-left: 6px;
      color: #ccc;
    }
  }
  .cancel-login-btn {
    font-size: 14px;
    text-align: center;
    margin: 21px;
    display: block;
    color: blue;
  }

</style>